using UnityEngine;

namespace EntityKit.Runtime
{
    public class BindBehaviour : MonoBehaviour
    {
        private bool m_IsBound = false;
        
        protected virtual void Awake()
        {
            PerformBinding();
        }

        protected virtual void OnDestroy()
        {
            BindService.Unbind(this);
        }
        
        protected void PerformBinding()
        {
            if (!m_IsBound)
            {
                BindService.AutoBind(this);
                m_IsBound = true;
            }
        }
    }
}